// ManualBot.cpp : Defines the entry point for the console application.
//

#define _CRT_SECURE_NO_DEPRECATE 1
#include "stdafx.h"

int _tmain(int argc, char* argv[])
{
	string pcHost;
	int nPort;

	if(argc < 2) {
		cout << "server: ";
		cin >> pcHost;
	}
	else {
		pcHost = argv[1];
	}
    if(argc < 3) {
		cout << "port: ";
		cin >> nPort;
	}
	else {
        nPort = atoi(argv[2]);
    }

	BZRC MyTeam = BZRC(pcHost.c_str(), nPort, false);
	if(!MyTeam.GetStatus()) {
		cout << "Can't connect to BZRC server." << endl;
		exit(1);
	}

	while (true)
	{
		// TODO: let the user pick which tank they are driving
		int tankindex = 0;

		SixAxisController* controller = SixAxisController::GetCurrentState();
		
		Vector2 left = controller->GetLeftAnalog();

		if (MyTeam.speed(tankindex, -left.y)) {
			//cout << "speed 0 " << -left.y << endl;
		} else {
			cout << "failed to move" << endl;
		}

		Vector2 right = controller->GetRightAnalog();
		
		if (MyTeam.angvel(tankindex, -right.x)) {
			//cout << "angvel 0 " << -right.x << endl;
		} else {
			cout << "failed to set angvel" << endl;
		}

		if (controller->IsButtonPressed(SixAxisController::BUTTON_08)) {
			if (MyTeam.shoot(tankindex)) {
				cout << "shot" << endl;
			} else {
				cout << "failed to shoot" << endl;
			}
		}

		delete controller;
	}

	MyTeam.Close();

	getchar();
	return 0;
} 

